package com.anysoft.fund;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.TextPaint;
import android.text.TextWatcher;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.anysoft.HostConstant;
import com.anysoft.R;
import com.anysoft.adapter.SearchAdapter;
import com.anysoft.base.BaseActivity;
import com.anysoft.bean.QueryFundListBean;
import com.anysoft.me.callback.StringDialogCallback;
import com.anysoft.utils.CommonUtil;
import com.anysoft.utils.HttpUtils;
import com.anysoft.utils.StringUtils;
import com.anysoft.web.FundDetailActivity;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.orhanobut.logger.Logger;
import com.squareup.otto.Subscribe;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by wwq on 2017/2/8.
 */

public class FundListAllActivity extends BaseActivity implements View.OnClickListener {

    private static final int FOF_TYPE_NUMBER = 707;
    @BindView(R.id.leftButton)
    Button leftButton;
    @BindView(R.id.rightButton)
    Button rightButton;
    @BindView(R.id.et_search)
    EditText etSearch;
    @BindView(R.id.lv)
    ListView lv;
    @BindView(R.id.ll_all_fund_search)
    LinearLayout llAllFundSearch;
    //    @BindView(R.id.tv_tips)
//    TextView tvTips;
//    @BindView(R.id.ll_tips)
//    LinearLayout ll_tips;
    @BindView(R.id.product_name_lly_all)
    LinearLayout productNameLlyAll;
    @BindView(R.id.llXuFu_all)
    LinearLayout llXuFuAll;
    @BindView(R.id.ll_all_fund_list)
    LinearLayout llAllFundList;

    private String json;

    @BindView(R.id.hsv_products_grounp)
    HorizontalScrollView hsv_products_grounp;
    @BindView(R.id.ll_products_grounp)
    LinearLayout ll_products_grounp;
    //屏幕宽度
    private int mScreenWidth;

    @BindView(R.id.ll_all)
    LinearLayout ll_all;
    @BindView(R.id.ll_fof)
    LinearLayout ll_fof;
    @BindView(R.id.ll_hb)
    LinearLayout ll_hb;
    @BindView(R.id.ll_lc)
    LinearLayout ll_lc;
    @BindView(R.id.ll_gp)
    LinearLayout ll_gp;
    @BindView(R.id.ll_zq)
    LinearLayout ll_zq;
    @BindView(R.id.ll_zs)
    LinearLayout ll_zs;
    @BindView(R.id.ll_hh)
    LinearLayout ll_hh;
    @BindView(R.id.ll_QD)
    LinearLayout ll_QD;
    private ArrayList<LinearLayout> ll_lists = new ArrayList<>();

    @BindView(R.id.tv_all)
    TextView tv_all;
    @BindView(R.id.tv_fof)
    TextView tv_fof;
    @BindView(R.id.tv_hb)
    TextView tv_hb;
    @BindView(R.id.tv_lc)
    TextView tv_lc;
    @BindView(R.id.tv_gp)
    TextView tv_gp;
    @BindView(R.id.tv_zq)
    TextView tv_zq;
    @BindView(R.id.tv_zs)
    TextView tv_zs;
    @BindView(R.id.tv_hh)
    TextView tv_hh;
    @BindView(R.id.tv_QD)
    TextView tv_QD;
    private ArrayList<TextView> tv_lists = new ArrayList<>();

    @BindView(R.id.iv_all)
    ImageView iv_all;
    @BindView(R.id.iv_fof)
    ImageView iv_fof;
    @BindView(R.id.iv_hb)
    ImageView iv_hb;
    @BindView(R.id.iv_lc)
    ImageView iv_lc;
    @BindView(R.id.iv_gp)
    ImageView iv_gp;
    @BindView(R.id.iv_zq)
    ImageView iv_zq;
    @BindView(R.id.iv_zs)
    ImageView iv_zs;
    @BindView(R.id.iv_hh)
    ImageView iv_hh;
    @BindView(R.id.iv_QD)
    ImageView iv_QD;
    private ArrayList<ImageView> iv_lists = new ArrayList<>();

    private ListView lv_fof;
    private ListView lv_hb;
    private ListView lv_lc;
    private ListView lv_gp;
    private ListView lv_zq;
    private ListView lv_zs;
    private ListView lv_hh;
    private ListView lv_QD;

    @BindView(R.id.rl_all)
    RelativeLayout rl_all;
    @BindView(R.id.tv_noInfo)
    TextView tv_noInfo;
    @BindView(R.id.ll_item_fof)
    LinearLayout ll_item_fof;
    @BindView(R.id.ll_item_hb)
    LinearLayout ll_item_hb;
    @BindView(R.id.ll_item_lc)
    LinearLayout ll_item_lc;
    @BindView(R.id.ll_item_gp)
    LinearLayout ll_item_gp;
    @BindView(R.id.ll_item_zq)
    LinearLayout ll_item_zq;
    @BindView(R.id.ll_item_zs)
    LinearLayout ll_item_zs;
    @BindView(R.id.ll_item_hh)
    LinearLayout ll_item_hh;
    @BindView(R.id.ll_item_QD)
    LinearLayout ll_item_QD;
    private ArrayList<View> visibileList = new ArrayList<>();

    @BindView(R.id.product_name_txt_all)
    TextView product_name_txt_all;
    @BindView(R.id.rl_B_1_all)
    RelativeLayout rl_B_1_all;
    @BindView(R.id.rl_B_2_all)
    RelativeLayout rl_B_2_all;
    @BindView(R.id.rl_B_3_all)
    RelativeLayout rl_B_3_all;
    @BindView(R.id.rl_B_4_all)
    RelativeLayout rl_B_4_all;
    @BindView(R.id.rl_B_5_all)
    RelativeLayout rl_B_5_all;
    @BindView(R.id.rl_B_6_all)
    RelativeLayout rl_B_6_all;
    @BindView(R.id.rl_B_7_all)
    RelativeLayout rl_B_7_all;
    @BindView(R.id.rl_B_8_all)
    RelativeLayout rl_B_8_all;
    @BindView(R.id.tv_B_1_all)
    TextView tv_B_1_all;
    @BindView(R.id.tv_B_2_all)
    TextView tv_B_2_all;
    @BindView(R.id.tv_B_3_all)
    TextView tv_B_3_all;
    @BindView(R.id.tv_B_4_all)
    TextView tv_B_4_all;
    @BindView(R.id.tv_B_5_all)
    TextView tv_B_5_all;
    @BindView(R.id.tv_B_6_all)
    TextView tv_B_6_all;
    @BindView(R.id.tv_B_7_all)
    TextView tv_B_7_all;
    @BindView(R.id.tv_B_8_all)
    TextView tv_B_8_all;
    @BindView(R.id.img_B_1_all)
    ImageView img_B_1_all;
    @BindView(R.id.img_B_2_all)
    ImageView img_B_2_all;
    @BindView(R.id.img_B_3_all)
    ImageView img_B_3_all;
    @BindView(R.id.img_B_4_all)
    ImageView img_B_4_all;
    @BindView(R.id.img_B_5_all)
    ImageView img_B_5_all;
    @BindView(R.id.img_B_6_all)
    ImageView img_B_6_all;
    @BindView(R.id.img_B_7_all)
    ImageView img_B_7_all;
    @BindView(R.id.img_B_8_all)
    ImageView img_B_8_all;
    @BindView(R.id.item_scroll_title_all)
    CHScrollView_All item_scroll_title_all;
    @BindView(R.id.hlistview_scroll_list_all)
    ExpandableListView hlistview_scroll_list_all;
    private ArrayList<ImageView> img_list_all = new ArrayList<>();
    /**
     * 0代表默认状态，1代表降序，2代表升序
     */
    private int[] group_state_1_all = {0, 1, 0, 0, 0, 0, 0, 0};
    /**
     * 0代表默认状态，1代表降序，2代表升序
     */
    private int[] group_state_2_all = {0, 1, 0, 0, 0, 0, 0, 0};
    private int sortPosition_1_all = 1;
    private int sortPosition_2_all = 1;
    private boolean isSortDown_1_all = true;
    private boolean isSortDown_2_all = true;
    private CHAdapterAll adapterAll;
    private boolean canChange_all = true;
    private int current_X_all = 0;
    private int current_Y_all = 0;

    private ScrollAdapter fofAdapter;
    private boolean canChange_fof = true;
    private int current_X_fof = 0;
    private int current_Y_fof = 0;
    private ScrollAdapter hbAdapter;
    private boolean canChange_hb = true;
    private int current_X_hb = 0;
    private int current_Y_hb = 0;
    private ScrollAdapter lcAdapter;
    private boolean canChange_lc = true;
    private int current_X_lc = 0;
    private int current_Y_lc = 0;
    private ScrollAdapter gpAdapter;
    private boolean canChange_gp = true;
    private int current_X_gp = 0;
    private int current_Y_gp = 0;
    private ScrollAdapter zqAdapter;
    private boolean canChange_zq = true;
    private int current_X_zq = 0;
    private int current_Y_zq = 0;
    private ScrollAdapter zsAdapter;
    private boolean canChange_zs = true;
    private int current_X_zs = 0;
    private int current_Y_zs = 0;
    private ScrollAdapter hhAdapter;
    private boolean canChange_hh = true;
    private int current_X_hh = 0;
    private int current_Y_hh = 0;
    private ScrollAdapter QDAdapter;
    private boolean canChange_QD = true;
    private int current_X_QD = 0;
    private int current_Y_QD = 0;

    private boolean isFirstALL = false;
    private boolean isFirstFOF = false;
    private boolean isFirstHB = false;
    private boolean isFirstLC = false;
    private boolean isFirstGP = false;
    private boolean isFirstZQ = false;
    private boolean isFirstZS = false;
    private boolean isFirstHH = false;
    private boolean isFirstQD = false;

    private boolean isSortDown_fof = true;
    private int sortPosition_fof = 2;
    private boolean isSortDown_hb = true;
    private int sortPosition_hb = 2;
    private boolean isSortDown_lc = true;
    private int sortPosition_lc = 2;
    private boolean isSortDown_gp = true;
    private int sortPosition_gp = 2;
    private boolean isSortDown_zq = true;
    private int sortPosition_zq = 2;
    private boolean isSortDown_zs = true;
    private int sortPosition_zs = 2;
    private boolean isSortDown_hh = true;
    private int sortPosition_hh = 2;
    private boolean isSortDown_QD = true;
    private int sortPosition_QD = 2;

    /**
     * 0-热门推荐 1-我的关注 2-货币基金 3-理财产品 4-股票基金 5-债券基金 6-指数基金 7-混合型 8-QDII 9-全部基金
     * 10-FOF
     */
    private int currentType = 0;

    public HorizontalScrollView mTouchView;
    protected List<CHScrollView_All> mHScrollViews_all = new ArrayList<>();
    protected List<CHScrollView_Others> mHScrollViews_fof = new ArrayList<>();
    protected List<CHScrollView_Others> mHScrollViews_hb = new ArrayList<>();
    protected List<CHScrollView_Others> mHScrollViews_lc = new ArrayList<>();
    protected List<CHScrollView_Others> mHScrollViews_gp = new ArrayList<>();
    protected List<CHScrollView_Others> mHScrollViews_zq = new ArrayList<>();
    protected List<CHScrollView_Others> mHScrollViews_zs = new ArrayList<>();
    protected List<CHScrollView_Others> mHScrollViews_hh = new ArrayList<>();
    protected List<CHScrollView_Others> mHScrollViews_QD = new ArrayList<>();

    private String[] cols = new String[]{"title", "data_1", "data_2", "data_3", "data_4", "data_5", "data_6",
            "data_7", "data_8"};

    private ArrayList<QueryFundListBean.DataBean> list_all = new ArrayList<>();
    private ArrayList<QueryFundListBean.DataBean> list_all_01 = new ArrayList<>();
    private ArrayList<QueryFundListBean.DataBean> list_all_02 = new ArrayList<>();

    private ArrayList<QueryFundListBean.DataBean> list_fof = new ArrayList<>();
    private ArrayList<QueryFundListBean.DataBean> list_hb = new ArrayList<>();
    private ArrayList<QueryFundListBean.DataBean> list_lc = new ArrayList<>();
    private ArrayList<QueryFundListBean.DataBean> list_gp = new ArrayList<>();
    private ArrayList<QueryFundListBean.DataBean> list_zq = new ArrayList<>();
    private ArrayList<QueryFundListBean.DataBean> list_zs = new ArrayList<>();
    private ArrayList<QueryFundListBean.DataBean> list_hh = new ArrayList<>();
    private ArrayList<QueryFundListBean.DataBean> list_QD = new ArrayList<>();

    private ArrayList<RelativeLayout> rl_alls = new ArrayList<>();

    private boolean isLoadSuccess = false;

    private ArrayList<QueryFundListBean.DataBean> searchLists = new ArrayList<>();
    private SearchAdapter searchAdapter;

    @Override
    public void onStart() {
        super.onStart();
        BusProvider.getInstance().register(this);
    }

    @SuppressWarnings("deprecation")
    @Override
    public void onStop() {
        super.onStop();
        BusProvider.getInstance().unregister(this);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_fund_list);
        ButterKnife.bind(this);
        getIntentValue();
        etSearch.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence arg0, int num1, int num2, int num3) {
                searchLists.clear();
                if (num1 == 0 && num3 == 0) {
                    llAllFundSearch.setVisibility(View.GONE);
                    llAllFundList.setVisibility(View.VISIBLE);
                }
                if (num3 != 0 || (num1 != 0 && num2 == 1)) {
                    llAllFundSearch.setVisibility(View.VISIBLE);
                    llAllFundList.setVisibility(View.GONE);
                    String searchStr = etSearch.getText().toString();
                    if (!StringUtils.isNullOrEmpty(searchStr)) {
                        searchStr = searchStr.toUpperCase();
                    }
                    searchAdapter.setSearchStr(searchStr);
                    for (QueryFundListBean.DataBean fundBean : list_all) {
                        if (fundBean.getFundcode().toUpperCase().contains(searchStr) || fundBean.getFundname().toUpperCase().contains(searchStr)) {
                            searchLists.add(fundBean);
                        }
                    }
                }
                searchAdapter.notifyDataSetChanged();
            }

            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            }

            @Override
            public void afterTextChanged(Editable arg0) {
            }
        });

        etSearch.setCursorVisible(false);

        etSearch.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                etSearch.setCursorVisible(true);
                return false;
            }
        });

        hsv_products_grounp = (HorizontalScrollView) findViewById(R.id.hsv_products_grounp);
        ll_products_grounp = (LinearLayout) findViewById(R.id.ll_products_grounp);
        mScreenWidth = getResources().getDisplayMetrics().widthPixels;

        //基金描述的容器的集合
        ll_lists.add(ll_fof);
        ll_lists.add(ll_hb);
        ll_lists.add(ll_lc);
        ll_lists.add(ll_gp);
        ll_lists.add(ll_zq);
        ll_lists.add(ll_zs);
        ll_lists.add(ll_hh);
        ll_lists.add(ll_QD);
        ll_lists.add(ll_all);

        ll_all.setOnClickListener(this);
        ll_fof.setOnClickListener(this);
        ll_hb.setOnClickListener(this);
        ll_lc.setOnClickListener(this);
        ll_gp.setOnClickListener(this);
        ll_zq.setOnClickListener(this);
        ll_zs.setOnClickListener(this);
        ll_hh.setOnClickListener(this);
        ll_QD.setOnClickListener(this);

        //基金描述的集合
        tv_lists.add(tv_fof);
        tv_lists.add(tv_hb);
        tv_lists.add(tv_lc);
        tv_lists.add(tv_gp);
        tv_lists.add(tv_zq);
        tv_lists.add(tv_zs);
        tv_lists.add(tv_hh);
        tv_lists.add(tv_QD);
        tv_lists.add(tv_all);
        //基金描述下划线的集合
        iv_lists.add(iv_fof);
        iv_lists.add(iv_hb);
        iv_lists.add(iv_lc);
        iv_lists.add(iv_gp);
        iv_lists.add(iv_zq);
        iv_lists.add(iv_zs);
        iv_lists.add(iv_hh);
        iv_lists.add(iv_QD);
        iv_lists.add(iv_all);

        visibileList.add(rl_all);
        visibileList.add(tv_noInfo);
        visibileList.add(ll_item_fof);
        visibileList.add(ll_item_hb);
        visibileList.add(ll_item_lc);
        visibileList.add(ll_item_gp);
        visibileList.add(ll_item_zq);
        visibileList.add(ll_item_zs);
        visibileList.add(ll_item_hh);
        visibileList.add(ll_item_QD);

        rl_alls.add(rl_B_1_all);
        rl_alls.add(rl_B_2_all);
        rl_alls.add(rl_B_3_all);
        rl_alls.add(rl_B_4_all);
        rl_alls.add(rl_B_5_all);
        rl_alls.add(rl_B_6_all);
        rl_alls.add(rl_B_7_all);
        rl_alls.add(rl_B_8_all);

        tv_B_3_all.setText("近1周");
        tv_B_4_all.setText("近1月");
        tv_B_5_all.setText("近3月");
        tv_B_6_all.setText("近6月");
        tv_B_7_all.setText("今年以来");
        tv_B_8_all.setText("成立以来");

        img_list_all.add(img_B_1_all);
        img_list_all.add(img_B_2_all);
        img_list_all.add(img_B_3_all);
        img_list_all.add(img_B_4_all);
        img_list_all.add(img_B_5_all);
        img_list_all.add(img_B_6_all);
        img_list_all.add(img_B_7_all);
        img_list_all.add(img_B_8_all);

//        new Thread(new ThreadClose()).start();

        etSearch.setFocusableInTouchMode(false);

        getInfos();

        // 默认选中第一个
        ll_products_grounp.getChildAt(0).setSelected(true);
        initEvents();
    }
    private int currentTabIndex;
    private void getIntentValue() {
        currentTabIndex =  getIntent().getIntExtra("currentType", 0);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    private void initEvents() {
        int childCount = ll_products_grounp.getChildCount();
        for (int i = 0; i < childCount; i++) {
            /**此index包含了隐藏的控件*/
            final int curIndex = i;
            View child = ll_products_grounp.getChildAt(i);
            // 添加点击事件
            child.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    collapseSoftInputMethod(view.getWindowToken());
                    selectTab(curIndex);
                    Logger.t(TAG).d("curIndex-----" + curIndex);
                    changeSelectTab(curIndex);
                    etSearch.setCursorVisible(false);
                }
            });
        }
    }

    private void changeSelectTab(int index) {
        switch (index) {
            case 0:
                clickChange(tv_all, iv_all);
                currentType = 9;

                if (isLoadSuccess) {
                    viewVisibile(11);
                    if (!isFirstALL) {
                        isFirstALL = true;
                        initMultipleFundList(rl_all, list_all_01, list_all_02, list_all, rl_alls
                                , product_name_txt_all);
                        initView_all();
                    }
                } else {
                    getInfos();
                }
                break;
            case 1:
                clickChange(tv_fof, iv_fof);
                currentType = 10;

                if (isLoadSuccess) {
                    viewVisibile(12);
                    if (!isFirstFOF) {
                        initSingleFundList(10);
                    }
                } else {
                    getInfos();
                }
                break;
            case 2:
                clickChange(tv_hb, iv_hb);
                currentType = 2;

                if (isLoadSuccess) {
                    viewVisibile(3);
                    if (!isFirstHB) {
                        initSingleFundList(2);
                    }
                } else {
                    getInfos();
                }
                break;
            case 3:
                clickChange(tv_lc, iv_lc);
                currentType = 3;

                if (isLoadSuccess) {
                    viewVisibile(4);
                    if (!isFirstLC) {
                        initSingleFundList(3);
                    }
                } else {
                    getInfos();
                }
                break;
            case 4:
                clickChange(tv_gp, iv_gp);
                currentType = 4;

                if (isLoadSuccess) {
                    viewVisibile(5);
                    if (!isFirstGP) {
                        initSingleFundList(4);
                    }
                } else {
                    getInfos();
                }
                break;
            case 5:
                clickChange(tv_zq, iv_zq);
                currentType = 5;

                if (isLoadSuccess) {
                    viewVisibile(6);
                    if (!isFirstZQ) {
                        initSingleFundList(5);
                    }
                } else {
                    getInfos();
                }
                break;
            case 6:
                clickChange(tv_zs, iv_zs);
                currentType = 6;

                if (isLoadSuccess) {
                    viewVisibile(7);
                    if (!isFirstZS) {
                        initSingleFundList(6);
                    }
                } else {
                    getInfos();
                }
                break;
            case 7:
                clickChange(tv_hh, iv_hh);
                currentType = 7;

                if (isLoadSuccess) {
                    viewVisibile(8);
                    if (!isFirstHH) {
                        initSingleFundList(7);
                    }
                } else {
                    getInfos();
                }
                break;
            case 8:
                currentType = 8;
                clickChange(tv_QD, iv_QD);

                if (isLoadSuccess) {
                    viewVisibile(9);
                    if (!isFirstQD) {
                        initSingleFundList(8);
                    }
                } else {
                    getInfos();
                }
                break;
            default:
                break;
        }
    }

    /**
     * 选中索引值为curIndex的tab
     *
     * @param curIndex
     */
    protected void selectTab(int curIndex) {
        int childCount = ll_products_grounp.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View child = ll_products_grounp.getChildAt(i);
            //设置选中状态
            child.setSelected(i == curIndex);
        }


        View curTabView = ll_products_grounp.getChildAt(curIndex);
        //获取x的值
        int left = curTabView.getLeft();
        int width = curTabView.getMeasuredWidth();
        int toX = left + width / 2 - mScreenWidth / 2;
        //滚动
        hsv_products_grounp.smoothScrollTo(toX, 0);
    }

//    // handler类接收数据
//    Handler handler = new Handler() {
//        public void handleMessage(Message msg) {
//            if (msg.what == 1) {
//                ll_tips.setVisibility(View.GONE);
//            }
//        }
//    };

    @OnClick({R.id.leftButton, R.id.rightButton})
    public void onClickview(View view) {
        collapseSoftInputMethod(view.getWindowToken());
        switch (view.getId()) {
            case R.id.leftButton:
                if (llAllFundSearch.isShown()) {
                    etSearch.setText("");
                    etSearch.setCursorVisible(false);
                } else {
                    finish();
                }
                break;
            case R.id.rightButton:
//                callCustomerServiceTelephoneNumbers();
                etSearch.setCursorVisible(false);
//                if (mentorApplication.needLogin()) {
//                    ActivityUtils.gotoLogin(mActivity, getSp(), hasUser(), false, findUserId());
//                } else {
                onlineCustomer();
//                }
                break;
        }
    }

//    // 线程类
//    class ThreadClose implements Runnable {
//
//        @Override
//        public void run() {
//            while (true) {
//                try {
//                    Thread.sleep(5000);
//                    Message msg = new Message();
//                    msg.what = 1;
//                    handler.sendMessage(msg);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//        }
//    }

    /**
     * 获取数据
     */
    private void getInfos() {
        OkGo.<String>post(HostConstant.QUERY_FUNDLIST)
                .tag(this)
                .params(HttpUtils.getCommonParams(this, null))
                .execute(new StringDialogCallback(this) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        json = response.body();
                        UpdateUI(response.body());
                    }


                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        showToast("网络加载失败，请稍后再试!");
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                    }
                });
    }


    private void UpdateUI(String resultJson) {
        QueryFundListBean bean;
        try {
            bean = new Gson().fromJson(resultJson, QueryFundListBean.class);
        } catch (Exception e) {
            Logger.e(TAG, "Gson解析数据时发生异常");
            e.printStackTrace();
            return;
        }

        if (!CommonUtil.checkState(mActivity, bean, json)) {
            return;
        }

        if (bean == null || bean.getData() == null || bean.getData().isEmpty() || bean.getData().size() < 1) {
            showConfirmAlert(mActivity, "数据为空");
            return;
        }

        list_all.clear();
        list_fof.clear();
        list_hb.clear();
        list_zs.clear();
        list_gp.clear();
        list_QD.clear();
        list_hh.clear();
        list_lc.clear();
        list_zq.clear();
        isLoadSuccess = true;

        ArrayList<QueryFundListBean.DataBean> map_fof = new ArrayList<>();
        ArrayList<QueryFundListBean.DataBean> map_hb = new ArrayList<>();
        ArrayList<QueryFundListBean.DataBean> map_zs = new ArrayList<>();
        ArrayList<QueryFundListBean.DataBean> map_gp = new ArrayList<>();
        ArrayList<QueryFundListBean.DataBean> map_QD = new ArrayList<>();
        ArrayList<QueryFundListBean.DataBean> map_hh = new ArrayList<>();
        ArrayList<QueryFundListBean.DataBean> map_lc = new ArrayList<>();
        ArrayList<QueryFundListBean.DataBean> map_zq = new ArrayList<>();

        for (QueryFundListBean.DataBean DataBean : bean.getData()) {

            list_all.add(DataBean);

            /**
             * 0:股票型
             * 1:债券型
             * 2:货币型
             * 5:指数型
             * 7:混合型
             * 8:QDII基金
             * 9:短期理财
             */
            int fundtype;
            try {
                fundtype = Integer.parseInt(DataBean.getFundtype());
            } catch (Exception exception) {
                fundtype = -1;
            }

            switch (fundtype) {
                case 2:
                    map_hb.add(DataBean);
                    break;
                case 5:
                    map_zs.add(DataBean);
                    break;
                case 0:
                    map_gp.add(DataBean);
                    break;
                case 8:
                    map_QD.add(DataBean);
                    break;
                case 7:
                    map_hh.add(DataBean);
                    break;
                case FOF_TYPE_NUMBER:
                    map_fof.add(DataBean);
                    break;
                case 9:
                    map_lc.add(DataBean);
                    break;
                case 1:
                    map_zq.add(DataBean);
                    break;

                default:
                    break;
            }
        }

        list_fof.addAll(FundListSortUtils.sortListDown(map_fof, 0, 1));
        list_hb.addAll(FundListSortUtils.sortListDown(map_hb, 0, 1));
        list_zs.addAll(FundListSortUtils.sortListDown(map_zs, 0, 1));
        list_gp.addAll(FundListSortUtils.sortListDown(map_gp, 0, 1));
        list_QD.addAll(FundListSortUtils.sortListDown(map_QD, 0, 1));
        list_hh.addAll(FundListSortUtils.sortListDown(map_hh, 0, 1));
        list_lc.addAll(FundListSortUtils.sortListDown(map_lc, 0, 1));
        list_zq.addAll(FundListSortUtils.sortListDown(map_zq, 0, 1));

        if (list_fof.size() > 0) {
            ll_fof.setVisibility(View.VISIBLE);
        }

        searchAdapter = new SearchAdapter(this, searchLists);
        lv.setAdapter(searchAdapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
                collapseSoftInputMethod(lv.getWindowToken());

                gotoDetails(searchLists.get(position));
            }
        });

        initSingleFundList(currentType);

        changeSelectTab(currentTabIndex);

        etSearch.setFocusable(true);
        etSearch.setFocusableInTouchMode(true);
        etSearch.requestFocus();
        etSearch.findFocus();
    }

    /**
     * 多类基金初始化
     *
     * @param mRelativeLayout
     * @param mFundInfosBeen_01
     * @param mFundInfosBeen_02
     * @param mFundInfosBeen
     * @param relativeLayouts
     * @param product_name_txt
     */
    private void initMultipleFundList(RelativeLayout mRelativeLayout, ArrayList<QueryFundListBean.DataBean> mFundInfosBeen_01,
                                      ArrayList<QueryFundListBean.DataBean> mFundInfosBeen_02, ArrayList<QueryFundListBean.DataBean> mFundInfosBeen,
                                      List<RelativeLayout> relativeLayouts, final TextView product_name_txt) {
        if (mRelativeLayout != null) {
            mRelativeLayout.setVisibility(View.VISIBLE);
        }

        ArrayList<QueryFundListBean.DataBean> map1 = new ArrayList<>();
        ArrayList<QueryFundListBean.DataBean> map2 = new ArrayList<>();
        if (mFundInfosBeen != null) {
            for (int i = 0; i < mFundInfosBeen.size(); i++) {

                switch (Integer.parseInt(mFundInfosBeen.get(i).getGroupNum())) {
                    case 1:
                        map1.add(mFundInfosBeen.get(i));
                        break;
                    case 2:
                        map2.add(mFundInfosBeen.get(i));
                        break;

                    default:
                        break;
                }
            }
        }

        if (mFundInfosBeen_01 != null) {
            mFundInfosBeen_01.clear();
            mFundInfosBeen_01.addAll(FundListSortUtils.sortListDown(map1, 1, 0));
        }
        if (mFundInfosBeen_02 != null) {
            mFundInfosBeen_02.clear();
            mFundInfosBeen_02.addAll(FundListSortUtils.sortListDown(map2, 1, 1));
        }

        FundInfosGroup group_01 = new FundInfosGroup();
        FundInfosGroup group_02 = new FundInfosGroup();
        group_01.fundInfosBeans = mFundInfosBeen_01;
        group_02.fundInfosBeans = mFundInfosBeen_02;

        // 添加头滑动事件
        mHScrollViews_all.clear();
        mHScrollViews_all.add(item_scroll_title_all);
        groupList_all = new ArrayList<>();

        if (mFundInfosBeen_01 != null && mFundInfosBeen_01.size() > 0) {
            groupList_all.add(group_01);
        }
        if (mFundInfosBeen_02 != null && mFundInfosBeen_02.size() > 0) {
            groupList_all.add(group_02);
        }

        for (int i = 0; i < relativeLayouts.size(); i++) {
            final int position = i;
            relativeLayouts.get(i).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    collapseSoftInputMethod(v.getWindowToken());
                    Object obj = product_name_txt.getTag();
                    if (obj == null)
                        return;
                    initStates_all(Integer.parseInt(obj.toString()), position);
                    changeImg(Integer.parseInt(obj.toString()), group_state_1_all, group_state_2_all, img_list_all);
//                        changeImg_all(Integer.parseInt(obj.toString()));

                }
            });
        }
    }


    private void changeImg(int group, int[] group_state_1, int[] group_state_2, ArrayList<ImageView> img_list) {
        switch (group) {
            case 0:
                for (int i = 0; i < group_state_1.length; i++) {
                    switch (group_state_1[i]) {
                        case 0:
                            img_list.get(i).setImageDrawable(getResources().getDrawable(R.mipmap.icon_angle));
                            break;
                        case 1:
                            img_list.get(i).setImageDrawable(getResources().getDrawable(R.mipmap.icon_rank_down));
                            break;
                        case 2:
                            img_list.get(i).setImageDrawable(getResources().getDrawable(R.mipmap.icon_rank_up));
                            break;
                        default:
                            break;
                    }
                }
                break;
            case 1:
                for (int i = 0; i < group_state_2.length; i++) {
                    switch (group_state_2[i]) {
                        case 0:
                            img_list.get(i).setImageDrawable(getResources().getDrawable(R.mipmap.icon_angle));
                            break;
                        case 1:
                            img_list.get(i).setImageDrawable(getResources().getDrawable(R.mipmap.icon_rank_down));
                            break;
                        case 2:
                            img_list.get(i).setImageDrawable(getResources().getDrawable(R.mipmap.icon_rank_up));
                            break;
                        default:
                            break;
                    }
                }
                break;

            default:
                break;
        }

    }


    List<FundInfosGroup> groupList_all;

    private void orderByData_all(int groupIndex, int clickPosition, boolean isSortDown) {
        ArrayList<QueryFundListBean.DataBean> maps = new ArrayList<>();
        switch (groupIndex) {
            case 0:
                if (isSortDown) {
                    maps.addAll(FundListSortUtils.sortListDown(list_all_01, clickPosition, groupIndex));
                } else {
                    maps.addAll(FundListSortUtils.sortListUp(list_all_01, clickPosition, groupIndex));
                }
                list_all_01.clear();
                list_all_01.addAll(maps);
                break;
            case 1:
                if (isSortDown) {
                    maps.addAll(FundListSortUtils.sortListDown(list_all_02, clickPosition, groupIndex));
                } else {
                    maps.addAll(FundListSortUtils.sortListUp(list_all_02, clickPosition, groupIndex));
                }
                list_all_02.clear();
                list_all_02.addAll(maps);
                break;

            default:
                break;
        }
        adapterAll.notifyDataSetChanged();
    }

    private void initStates_all(int group, int clickPosition) {
        switch (group) {
            case 0:
                if (clickPosition != sortPosition_1_all) {
                    sortPosition_1_all = clickPosition;
                    isSortDown_1_all = true;
                } else {
                    isSortDown_1_all = !isSortDown_1_all;
                }
                for (int i = 0; i < group_state_1_all.length; i++) {
                    group_state_1_all[i] = 0;
                }
                if (isSortDown_1_all) {
                    group_state_1_all[clickPosition] = 1;
                } else {
                    group_state_1_all[clickPosition] = 2;
                }
                orderByData_all(group, clickPosition, isSortDown_1_all);
                break;
            case 1:
                if (clickPosition != sortPosition_2_all) {
                    sortPosition_2_all = clickPosition;
                    isSortDown_2_all = true;
                } else {
                    isSortDown_2_all = !isSortDown_2_all;
                }
                for (int i = 0; i < group_state_2_all.length; i++) {
                    group_state_2_all[i] = 0;
                }
                if (isSortDown_2_all) {
                    group_state_2_all[clickPosition] = 1;
                } else {
                    group_state_2_all[clickPosition] = 2;
                }
                orderByData_all(group, clickPosition, isSortDown_2_all);
                break;

            default:
                break;
        }
    }

    @Subscribe
    public void onScrollChange_all(OnScrollEvent_All event) {
        if (canChange_all) {
            Log.d("OnScrollEvent", "OnScrollEvent");
            current_X_all = event.getL();
            current_Y_all = event.getT();
            for (CHScrollView_All scrollView : mHScrollViews_all) {
                scrollView.smoothScrollTo(event.getL(), event.getT());
            }
        }
    }

    private void initView_all() {
        boolean isOnlyGroup2 = false;
        if (groupList_all.size() == 1) {
            if (list_all_01 != null && list_all_01.size() > 0) {
                isOnlyGroup2 = false;
            } else {
                isOnlyGroup2 = true;
            }
        }
        adapterAll = new CHAdapterAll(mActivity, groupList_all, mHScrollViews_all, group_state_1_all, group_state_2_all,
                isOnlyGroup2);
        adapterAll.setGoBackMethodListener(new CHAdapterAll.GoBackMethodListener_All() {

            @Override
            public void callBack(int group, int clickPosition) {
                initStates_all(group, clickPosition);
            }
        });

        adapterAll.SetOnFundDetailAllListener(new CHAdapterAll.OnFundDetailAllListener() {

            @Override
            public void OnDetailClick(QueryFundListBean.DataBean bean) {
                gotoDetails(bean);
            }
        });

        hlistview_scroll_list_all.setAdapter(adapterAll);
        for (int i = 0; i < adapterAll.getGroupCount(); i++) {
            hlistview_scroll_list_all.expandGroup(i);
        }

        hlistview_scroll_list_all.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                Log.e("ssss", "groupPosition=" + groupPosition + " id=" + id);
                return false;
            }
        });
        hlistview_scroll_list_all.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                                        long id) {

                Log.e("ssss", "groupPosition=" + groupPosition + " childPosition=" + childPosition);
                return false;
            }
        });
        hlistview_scroll_list_all.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                // scrollState:1--滑动开始，0--滑动结束,2--手指离开惯性滑动
                // TODO 用于将列表同步到位，测试看看有没有其他问题出现,到时候把推荐和关注的也改了，包括adapter
                if (scrollState == 1) {
                    for (CHScrollView_All scrollView : mHScrollViews_all) {
                        scrollView.smoothScrollTo(current_X_all, current_Y_all);
                        canChange_all = false;
                    }
                } else if (scrollState == 2) {
                    canChange_all = false;
                } else {
                    canChange_all = true;
                }
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                // TODO 用于将列表同步到位，测试看看有没有其他问题出现
                for (CHScrollView_All scrollView : mHScrollViews_all) {
                    scrollView.smoothScrollTo(current_X_all, current_Y_all);
                }
                int iTotalCount = 0;

                if (groupList_all.size() > 1) {
                    for (int i = 0; i < groupList_all.size(); i++) {
                        iTotalCount += (groupList_all.get(i).fundInfosBeans.size() + 1);
                        if (i == 0) {
                            if (firstVisibleItem < iTotalCount) {
                                product_name_txt_all.setText("基金名称");
                                tv_B_1_all.setText("最新净值");
                                tv_B_2_all.setText("日涨幅");
                                product_name_txt_all.setTag(0);
                                changeImg(0, group_state_1_all, group_state_2_all, img_list_all);
                            }
                        }
                        if ((firstVisibleItem) >= iTotalCount) {
                            product_name_txt_all.setText("基金名称");
                            tv_B_1_all.setText("万份收益");
                            tv_B_2_all.setText("七日年化");
                            product_name_txt_all.setTag(i + 1);
                            changeImg(i + 1, group_state_1_all, group_state_2_all, img_list_all);
                        }
                    }
                } else if (groupList_all.size() == 1) {
                    if (list_all_01 != null && list_all_01.size() > 0) {
                        product_name_txt_all.setText("基金名称");
                        tv_B_1_all.setText("最新净值");
                        tv_B_2_all.setText("日涨幅");
                        product_name_txt_all.setTag(0);
                        changeImg(0, group_state_1_all, group_state_2_all, img_list_all);
                    } else {
                        product_name_txt_all.setText("基金名称");
                        tv_B_1_all.setText("万份收益");
                        tv_B_2_all.setText("七日年化");
                        product_name_txt_all.setTag(1);
                        changeImg(1, group_state_1_all, group_state_2_all, img_list_all);
                    }
                }

            }
        });
    }

    /**
     * 基金的类型展示
     *
     * @param fundType
     */
    private void initSingleFundList(int fundType) {
        LayoutInflater inflater = LayoutInflater.from(mActivity);
        View itemView = inflater.inflate(R.layout.item_icbc_fundlist_body, null);
        CHScrollView_Others item_scroll_title = (CHScrollView_Others) itemView.findViewById(R.id.item_scroll_title);
        item_scroll_title.setType(fundType);

        //基金排序描述
        TextView tv_item_body_01 = (TextView) itemView.findViewById(R.id.tv_item_body_01);
        TextView tv_item_body_02 = (TextView) itemView.findViewById(R.id.tv_item_body_02);
        TextView tv_item_body_03 = (TextView) itemView.findViewById(R.id.tv_item_body_03);
        TextView tv_item_body_04 = (TextView) itemView.findViewById(R.id.tv_item_body_04);
        TextView tv_item_body_05 = (TextView) itemView.findViewById(R.id.tv_item_body_05);
        TextView tv_item_body_06 = (TextView) itemView.findViewById(R.id.tv_item_body_06);
        TextView tv_item_body_07 = (TextView) itemView.findViewById(R.id.tv_item_body_07);
        TextView tv_item_body_08 = (TextView) itemView.findViewById(R.id.tv_item_body_08);
        //基金排序描述的容器
        RelativeLayout rl_item_body_01 = (RelativeLayout) itemView.findViewById(R.id.rl_item_body_01);
        RelativeLayout rl_item_body_02 = (RelativeLayout) itemView.findViewById(R.id.rl_item_body_02);
        RelativeLayout rl_item_body_03 = (RelativeLayout) itemView.findViewById(R.id.rl_item_body_03);
        RelativeLayout rl_item_body_04 = (RelativeLayout) itemView.findViewById(R.id.rl_item_body_04);
        RelativeLayout rl_item_body_05 = (RelativeLayout) itemView.findViewById(R.id.rl_item_body_05);
        RelativeLayout rl_item_body_06 = (RelativeLayout) itemView.findViewById(R.id.rl_item_body_06);
        RelativeLayout rl_item_body_07 = (RelativeLayout) itemView.findViewById(R.id.rl_item_body_07);
        RelativeLayout rl_item_body_08 = (RelativeLayout) itemView.findViewById(R.id.rl_item_body_08);
        ArrayList<RelativeLayout> itemList = new ArrayList<>();
        itemList.add(rl_item_body_01);
        itemList.add(rl_item_body_02);
        itemList.add(rl_item_body_03);
        itemList.add(rl_item_body_04);
        itemList.add(rl_item_body_05);
        itemList.add(rl_item_body_06);
        itemList.add(rl_item_body_07);
        itemList.add(rl_item_body_08);

        //基金通用标识
        ImageView iv_item_body_01_common = (ImageView) itemView.findViewById(R.id.iv_item_body_01_common);
        ImageView iv_item_body_02_common = (ImageView) itemView.findViewById(R.id.iv_item_body_02_common);
        ImageView iv_item_body_03_common = (ImageView) itemView.findViewById(R.id.iv_item_body_03_common);
        ImageView iv_item_body_04_common = (ImageView) itemView.findViewById(R.id.iv_item_body_04_common);
        ImageView iv_item_body_05_common = (ImageView) itemView.findViewById(R.id.iv_item_body_05_common);
        ImageView iv_item_body_06_common = (ImageView) itemView.findViewById(R.id.iv_item_body_06_common);
        ImageView iv_item_body_07_common = (ImageView) itemView.findViewById(R.id.iv_item_body_07_common);
        ImageView iv_item_body_08_common = (ImageView) itemView.findViewById(R.id.iv_item_body_08_common);
        final ImageView[] commonList = {iv_item_body_01_common, iv_item_body_02_common, iv_item_body_03_common,
                iv_item_body_04_common, iv_item_body_05_common, iv_item_body_06_common, iv_item_body_07_common,
                iv_item_body_08_common};

        //基金排序标识,升序 or 降序
        ImageView iv_item_body_01_sort = (ImageView) itemView.findViewById(R.id.iv_item_body_01_sort);
        ImageView iv_item_body_02_sort = (ImageView) itemView.findViewById(R.id.iv_item_body_02_sort);
        ImageView iv_item_body_03_sort = (ImageView) itemView.findViewById(R.id.iv_item_body_03_sort);
        ImageView iv_item_body_04_sort = (ImageView) itemView.findViewById(R.id.iv_item_body_04_sort);
        ImageView iv_item_body_05_sort = (ImageView) itemView.findViewById(R.id.iv_item_body_05_sort);
        ImageView iv_item_body_06_sort = (ImageView) itemView.findViewById(R.id.iv_item_body_06_sort);
        ImageView iv_item_body_07_sort = (ImageView) itemView.findViewById(R.id.iv_item_body_07_sort);
        ImageView iv_item_body_08_sort = (ImageView) itemView.findViewById(R.id.iv_item_body_08_sort);
        final ImageView[] sortList = {iv_item_body_01_sort, iv_item_body_02_sort, iv_item_body_03_sort,
                iv_item_body_04_sort, iv_item_body_05_sort, iv_item_body_06_sort, iv_item_body_07_sort,
                iv_item_body_08_sort};

        switch (fundType) {
            case 2: //货币
                initHBList(item_scroll_title, itemList, commonList, sortList, itemView);
                break;
            case 3: //理财
                initLCList(item_scroll_title, itemList, commonList, sortList, itemView);
                break;
            case 4: //股票
                initGPList(item_scroll_title, itemList, commonList, sortList, itemView);
                break;
            case 5: //债券
                initZQList(item_scroll_title, itemList, commonList, sortList, itemView);
                break;
            case 6: //指数
                initZSList(item_scroll_title, itemList, commonList, sortList, itemView);
                break;
            case 7: //混合
                initHHList(item_scroll_title, itemList, commonList, sortList, itemView);
                break;
            case 8: //QDII
                initQDList(item_scroll_title, itemList, commonList, sortList, itemView);
                break;
            case 10: //FOF
                initFOFList(item_scroll_title, itemList, commonList, sortList, itemView);
                break;
            default:
                break;
        }

        switch (fundType) {
            case 2:
            case 3:
                tv_item_body_01.setText("万份收益");
                tv_item_body_02.setText("七日年化");
                break;
            default:
                tv_item_body_01.setText("最新净值");
                tv_item_body_02.setText("日涨幅");
                break;
        }

        tv_item_body_03.setText("近1周");
        tv_item_body_04.setText("近1月");
        tv_item_body_05.setText("近3月");
        tv_item_body_06.setText("近6月");
        tv_item_body_07.setText("今年以来");
        tv_item_body_08.setText("成立以来");
    }

    /**
     * 初始化货币基金列表
     *
     * @param item_scroll_title CHScrollView_Others
     * @param itemList          ArrayList<RelativeLayout> 基金排序描述的容器集合
     * @param commonList        ImageView[]  基金通用标识数组
     * @param sortList          ImageView[]  基金排序标识数组
     * @param itemView
     */
    @SuppressLint("InflateParams")
    private void initHBList(CHScrollView_Others item_scroll_title, ArrayList<RelativeLayout> itemList,
                            final ImageView[] commonList, final ImageView[] sortList, View itemView) {
        mHScrollViews_hb.add(item_scroll_title);

        for (int i = 0; i < itemList.size(); i++) {
            final int position = i;
            itemList.get(i).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    collapseSoftInputMethod(v.getWindowToken());
                    if ((position + 1) != sortPosition_hb) {
                        sortPosition_hb = position + 1;
                        isSortDown_hb = true;
                    } else {
                        isSortDown_hb = !isSortDown_hb;
                    }
                    sortImageChange(commonList, sortList, position, isSortDown_hb);
                    //
                    ArrayList<QueryFundListBean.DataBean> maps = new ArrayList<>();
                    if (isSortDown_hb) {
                        maps.addAll(FundListSortUtils.sortListDown(list_hb, position, 1));
                    } else {
                        maps.addAll(FundListSortUtils.sortListUp(list_hb, position, 1));
                    }
                    list_hb.clear();
                    list_hb.addAll(maps);
                    if (hbAdapter != null) {
                        hbAdapter.notifyDataSetChanged();
                    }
                }
            });
        }

        lv_hb = (ListView) itemView.findViewById(R.id.hlistview_scroll_list);
        ll_item_hb.addView(itemView);

        hbAdapter = new ScrollAdapter(mActivity, R.layout.common_item_hlistview,
                new int[]{R.id.item_titlev, R.id.item_datav1, R.id.item_datav2, R.id.item_datav3, R.id.item_datav4,
                        R.id.item_datav5, R.id.item_datav6, R.id.item_datav7, R.id.item_datav8, R.id.item_icon_new,
                        R.id.item_icon_tui, R.id.item_titlev_code, R.id.item_datav1_1},
                list_hb, 2, FundListAllActivity.this, mHScrollViews_hb, lv_hb);
        lv_hb.setAdapter(hbAdapter);

        lv_hb.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                // scrollState:1--滑动开始，0--滑动结束,2--手指离开惯性滑动
                if (scrollState == 1) {
                    for (CHScrollView_Others scrollView : mHScrollViews_hb) {
                        if (mTouchView != scrollView) {
                            scrollView.smoothScrollTo(current_X_hb, current_Y_hb);
                        }
                        canChange_hb = false;
                    }
                } else if (scrollState == 2) {
                    canChange_hb = false;
                } else {
                    canChange_hb = true;
                }
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            }
        });

        if (!isFirstHB) {
            sortImageChange(commonList, sortList, 1, isSortDown_hb);
            //
            ArrayList<QueryFundListBean.DataBean> maps = new ArrayList<>();
            if (isSortDown_hb) {
                maps.addAll(FundListSortUtils.sortListDown(list_hb, 1, 1));
            } else {
                maps.addAll(FundListSortUtils.sortListUp(list_hb, 1, 1));
            }
            list_hb.clear();
            list_hb.addAll(maps);
            if (hbAdapter != null) {
                hbAdapter.notifyDataSetChanged();
            }
        }
        isFirstHB = true;
    }

    /**
     * 初始化理财基金列表
     */
    @SuppressLint("InflateParams")
    private void initLCList(CHScrollView_Others item_scroll_title, ArrayList<RelativeLayout> itemList,
                            final ImageView[] commonList, final ImageView[] sortList, View itemView) {
        mHScrollViews_lc.add(item_scroll_title);

        for (int i = 0; i < itemList.size(); i++) {
            final int position = i;
            itemList.get(i).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    collapseSoftInputMethod(v.getWindowToken());
                    if ((position + 1) != sortPosition_lc) {
                        sortPosition_lc = position + 1;
                        isSortDown_lc = true;
                    } else {
                        isSortDown_lc = !isSortDown_lc;
                    }
                    sortImageChange(commonList, sortList, position, isSortDown_lc);
                    ArrayList<QueryFundListBean.DataBean> maps = new ArrayList<>();
                    if (isSortDown_lc) {
                        maps.addAll(FundListSortUtils.sortListDown(list_lc, position, 1));
                    } else {
                        maps.addAll(FundListSortUtils.sortListUp(list_lc, position, 1));
                    }
                    list_lc.clear();
                    list_lc.addAll(maps);
                    if (lcAdapter != null) {
                        lcAdapter.notifyDataSetChanged();
                    }
                }
            });
        }

        lv_lc = (ListView) itemView.findViewById(R.id.hlistview_scroll_list);
        ll_item_lc.addView(itemView);

        lcAdapter = new ScrollAdapter(mActivity, R.layout.common_item_hlistview,
                new int[]{R.id.item_titlev, R.id.item_datav1, R.id.item_datav2, R.id.item_datav3, R.id.item_datav4,
                        R.id.item_datav5, R.id.item_datav6, R.id.item_datav7, R.id.item_datav8, R.id.item_icon_new,
                        R.id.item_icon_tui, R.id.item_titlev_code, R.id.item_datav1_1},
                list_lc, 3, FundListAllActivity.this, mHScrollViews_lc, lv_lc);
        lv_lc.setAdapter(lcAdapter);

        lv_lc.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                // scrollState:1--滑动开始，0--滑动结束,2--手指离开惯性滑动
                if (scrollState == 1) {
                    for (CHScrollView_Others scrollView : mHScrollViews_lc) {
                        if (mTouchView != scrollView) {
                            scrollView.smoothScrollTo(current_X_lc, current_Y_lc);
                        }
                        canChange_lc = false;
                    }
                } else if (scrollState == 2) {
                    canChange_lc = false;
                } else {
                    canChange_lc = true;
                }
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            }
        });

        if (!isFirstLC) {
            sortImageChange(commonList, sortList, 1, isSortDown_lc);
            ArrayList<QueryFundListBean.DataBean> maps = new ArrayList<>();
            if (isSortDown_lc) {
                maps.addAll(FundListSortUtils.sortListDown(list_lc, 1, 1));
            } else {
                maps.addAll(FundListSortUtils.sortListUp(list_lc, 1, 1));
            }
            list_lc.clear();
            list_lc.addAll(maps);
            if (lcAdapter != null) {
                lcAdapter.notifyDataSetChanged();
            }
        }
        isFirstLC = true;
    }

    /**
     * 初始化FOF基金列表
     */
    @SuppressLint("InflateParams")
    private void initFOFList(CHScrollView_Others item_scroll_title, ArrayList<RelativeLayout> itemList,
                             final ImageView[] commonList, final ImageView[] sortList, View itemView) {
        mHScrollViews_fof.add(item_scroll_title);

        for (int i = 0; i < itemList.size(); i++) {
            final int position = i;
            itemList.get(i).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    collapseSoftInputMethod(v.getWindowToken());
                    if ((position + 1) != sortPosition_fof) {
                        sortPosition_fof = position + 1;
                        isSortDown_fof = true;
                    } else {
                        isSortDown_fof = !isSortDown_fof;
                    }
                    sortImageChange(commonList, sortList, position, isSortDown_fof);
                    ArrayList<QueryFundListBean.DataBean> maps = new ArrayList<>();
                    if (isSortDown_fof) {
                        maps.addAll(FundListSortUtils.sortListDown(list_fof, position, 0));
                    } else {
                        maps.addAll(FundListSortUtils.sortListUp(list_fof, position, 0));
                    }
                    list_fof.clear();
                    list_fof.addAll(maps);
                    if (fofAdapter != null) {
                        fofAdapter.notifyDataSetChanged();
                    }
                }
            });
        }

        lv_fof = (ListView) itemView.findViewById(R.id.hlistview_scroll_list);
        ll_item_fof.addView(itemView);

        fofAdapter = new ScrollAdapter(mActivity, R.layout.common_item_hlistview,
                new int[]{R.id.item_titlev, R.id.item_datav1, R.id.item_datav2, R.id.item_datav3, R.id.item_datav4,
                        R.id.item_datav5, R.id.item_datav6, R.id.item_datav7, R.id.item_datav8, R.id.item_icon_new,
                        R.id.item_icon_tui, R.id.item_titlev_code, R.id.item_datav1_1},
                list_fof, 10, FundListAllActivity.this, mHScrollViews_fof, lv_fof);
        lv_fof.setAdapter(fofAdapter);

        lv_fof.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                // scrollState:1--滑动开始，0--滑动结束,2--手指离开惯性滑动
                if (scrollState == 1) {
                    for (CHScrollView_Others scrollView : mHScrollViews_fof) {
                        if (mTouchView != scrollView) {
                            scrollView.smoothScrollTo(current_X_fof, current_Y_fof);
                        }
                        canChange_fof = false;
                    }
                } else if (scrollState == 2) {
                    canChange_fof = false;
                } else {
                    canChange_fof = true;
                }
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            }
        });

        if (!isFirstFOF) {
            sortImageChange(commonList, sortList, 1, isSortDown_fof);
            ArrayList<QueryFundListBean.DataBean> maps = new ArrayList<>();
            if (isSortDown_fof) {
                maps.addAll(FundListSortUtils.sortListDown(list_fof, 1, 0));
            } else {
                maps.addAll(FundListSortUtils.sortListUp(list_fof, 1, 0));
            }
            list_fof.clear();
            list_fof.addAll(maps);
            if (fofAdapter != null) {
                fofAdapter.notifyDataSetChanged();
            }
        }
        isFirstFOF = true;
    }

    /**
     * 初始化股票基金列表
     */
    @SuppressLint("InflateParams")
    private void initGPList(CHScrollView_Others item_scroll_title, ArrayList<RelativeLayout> itemList,
                            final ImageView[] commonList, final ImageView[] sortList, View itemView) {
        mHScrollViews_gp.add(item_scroll_title);

        for (int i = 0; i < itemList.size(); i++) {
            final int position = i;
            itemList.get(i).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    collapseSoftInputMethod(v.getWindowToken());
                    if ((position + 1) != sortPosition_gp) {
                        sortPosition_gp = position + 1;
                        isSortDown_gp = true;
                    } else {
                        isSortDown_gp = !isSortDown_gp;
                    }
                    sortImageChange(commonList, sortList, position, isSortDown_gp);
                    ArrayList<QueryFundListBean.DataBean> maps = new ArrayList<>();
                    if (isSortDown_gp) {
                        maps.addAll(FundListSortUtils.sortListDown(list_gp, position, 0));
                    } else {
                        maps.addAll(FundListSortUtils.sortListUp(list_gp, position, 0));
                    }
                    list_gp.clear();
                    list_gp.addAll(maps);
                    if (gpAdapter != null) {
                        gpAdapter.notifyDataSetChanged();
                    }
                }
            });
        }

        lv_gp = (ListView) itemView.findViewById(R.id.hlistview_scroll_list);
        ll_item_gp.addView(itemView);

        gpAdapter = new ScrollAdapter(mActivity, R.layout.common_item_hlistview,
                new int[]{R.id.item_titlev, R.id.item_datav1, R.id.item_datav2, R.id.item_datav3, R.id.item_datav4,
                        R.id.item_datav5, R.id.item_datav6, R.id.item_datav7, R.id.item_datav8, R.id.item_icon_new,
                        R.id.item_icon_tui, R.id.item_titlev_code, R.id.item_datav1_1},
                list_gp, 4, FundListAllActivity.this, mHScrollViews_gp, lv_gp);
        lv_gp.setAdapter(gpAdapter);

        lv_gp.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                // scrollState:1--滑动开始，0--滑动结束,2--手指离开惯性滑动
                if (scrollState == 1) {
                    for (CHScrollView_Others scrollView : mHScrollViews_gp) {
                        if (mTouchView != scrollView) {
                            scrollView.smoothScrollTo(current_X_gp, current_Y_gp);
                        }
                        canChange_gp = false;
                    }
                } else if (scrollState == 2) {
                    canChange_gp = false;
                } else {
                    canChange_gp = true;
                }
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            }
        });

        if (!isFirstGP) {
            sortImageChange(commonList, sortList, 1, isSortDown_gp);
            ArrayList<QueryFundListBean.DataBean> maps = new ArrayList<>();
            if (isSortDown_gp) {
                maps.addAll(FundListSortUtils.sortListDown(list_gp, 1, 0));
            } else {
                maps.addAll(FundListSortUtils.sortListUp(list_gp, 1, 0));
            }
            list_gp.clear();
            list_gp.addAll(maps);
            if (gpAdapter != null) {
                gpAdapter.notifyDataSetChanged();
            }
        }
        isFirstGP = true;
    }

    /**
     * 初始化债券基金列表
     */
    @SuppressLint("InflateParams")
    private void initZQList(CHScrollView_Others item_scroll_title, ArrayList<RelativeLayout> itemList,
                            final ImageView[] commonList, final ImageView[] sortList, View itemView) {
        mHScrollViews_zq.add(item_scroll_title);

        for (int i = 0; i < itemList.size(); i++) {
            final int position = i;
            itemList.get(i).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    collapseSoftInputMethod(v.getWindowToken());
                    if ((position + 1) != sortPosition_zq) {
                        sortPosition_zq = position + 1;
                        isSortDown_zq = true;
                    } else {
                        isSortDown_zq = !isSortDown_zq;
                    }
                    sortImageChange(commonList, sortList, position, isSortDown_zq);
                    ArrayList<QueryFundListBean.DataBean> maps = new ArrayList<>();
                    if (isSortDown_zq) {
                        maps.addAll(FundListSortUtils.sortListDown(list_zq, position, 0));
                    } else {
                        maps.addAll(FundListSortUtils.sortListUp(list_zq, position, 0));
                    }
                    list_zq.clear();
                    list_zq.addAll(maps);
                    if (zqAdapter != null) {
                        zqAdapter.notifyDataSetChanged();
                    }
                }
            });
        }

        lv_zq = (ListView) itemView.findViewById(R.id.hlistview_scroll_list);
        ll_item_zq.addView(itemView);

        zqAdapter = new ScrollAdapter(mActivity, R.layout.common_item_hlistview,
                new int[]{R.id.item_titlev, R.id.item_datav1, R.id.item_datav2, R.id.item_datav3, R.id.item_datav4,
                        R.id.item_datav5, R.id.item_datav6, R.id.item_datav7, R.id.item_datav8, R.id.item_icon_new,
                        R.id.item_icon_tui, R.id.item_titlev_code, R.id.item_datav1_1},
                list_zq, 5, FundListAllActivity.this, mHScrollViews_zq, lv_zq);
        lv_zq.setAdapter(zqAdapter);

        lv_zq.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                // scrollState:1--滑动开始，0--滑动结束,2--手指离开惯性滑动
                if (scrollState == 1) {
                    for (CHScrollView_Others scrollView : mHScrollViews_zq) {
                        if (mTouchView != scrollView) {
                            scrollView.smoothScrollTo(current_X_zq, current_Y_zq);
                        }
                        canChange_zq = false;
                    }
                } else if (scrollState == 2) {
                    canChange_zq = false;
                } else {
                    canChange_zq = true;
                }
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            }
        });

        if (!isFirstZQ) {
            sortImageChange(commonList, sortList, 1, isSortDown_zq);
            ArrayList<QueryFundListBean.DataBean> maps = new ArrayList<>();
            if (isSortDown_zq) {
                maps.addAll(FundListSortUtils.sortListDown(list_zq, 1, 0));
            } else {
                maps.addAll(FundListSortUtils.sortListUp(list_zq, 1, 0));
            }
            list_zq.clear();
            list_zq.addAll(maps);
            if (zqAdapter != null) {
                zqAdapter.notifyDataSetChanged();
            }
        }
        isFirstZQ = true;
    }

    /**
     * 初始化指数基金列表
     */
    @SuppressLint("InflateParams")
    private void initZSList(CHScrollView_Others item_scroll_title, ArrayList<RelativeLayout> itemList,
                            final ImageView[] commonList, final ImageView[] sortList, View itemView) {
        mHScrollViews_zs.add(item_scroll_title);

        for (int i = 0; i < itemList.size(); i++) {
            final int position = i;
            itemList.get(i).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    collapseSoftInputMethod(v.getWindowToken());
                    if ((position + 1) != sortPosition_zs) {
                        sortPosition_zs = position + 1;
                        isSortDown_zs = true;
                    } else {
                        isSortDown_zs = !isSortDown_zs;
                    }
                    sortImageChange(commonList, sortList, position, isSortDown_zs);
                    ArrayList<QueryFundListBean.DataBean> maps = new ArrayList<>();
                    if (isSortDown_zs) {
                        maps.addAll(FundListSortUtils.sortListDown(list_zs, position, 0));
                    } else {
                        maps.addAll(FundListSortUtils.sortListUp(list_zs, position, 0));
                    }
                    list_zs.clear();
                    list_zs.addAll(maps);
                    if (zsAdapter != null) {
                        zsAdapter.notifyDataSetChanged();
                    }
                }
            });
        }

        lv_zs = (ListView) itemView.findViewById(R.id.hlistview_scroll_list);
        ll_item_zs.addView(itemView);

        zsAdapter = new ScrollAdapter(mActivity, R.layout.common_item_hlistview,
                new int[]{R.id.item_titlev, R.id.item_datav1, R.id.item_datav2, R.id.item_datav3, R.id.item_datav4,
                        R.id.item_datav5, R.id.item_datav6, R.id.item_datav7, R.id.item_datav8, R.id.item_icon_new,
                        R.id.item_icon_tui, R.id.item_titlev_code, R.id.item_datav1_1},
                list_zs, 6, FundListAllActivity.this, mHScrollViews_zs, lv_zs);
        lv_zs.setAdapter(zsAdapter);

        lv_zs.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                // scrollState:1--滑动开始，0--滑动结束,2--手指离开惯性滑动
                if (scrollState == 1) {
                    for (CHScrollView_Others scrollView : mHScrollViews_zs) {
                        if (mTouchView != scrollView) {
                            scrollView.smoothScrollTo(current_X_zs, current_Y_zs);
                        }
                        canChange_zs = false;
                    }
                } else if (scrollState == 2) {
                    canChange_zs = false;
                } else {
                    canChange_zs = true;
                }
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            }
        });

        if (!isFirstZS) {
            sortImageChange(commonList, sortList, 1, isSortDown_zs);
            ArrayList<QueryFundListBean.DataBean> maps = new ArrayList<>();
            if (isSortDown_zs) {
                maps.addAll(FundListSortUtils.sortListDown(list_zs, 1, 0));
            } else {
                maps.addAll(FundListSortUtils.sortListUp(list_zs, 1, 0));
            }
            list_zs.clear();
            list_zs.addAll(maps);
            if (zsAdapter != null) {
                zsAdapter.notifyDataSetChanged();
            }
        }
        isFirstZS = true;
    }

    /**
     * 初始化混合基金列表
     */
    @SuppressLint("InflateParams")
    private void initHHList(CHScrollView_Others item_scroll_title, ArrayList<RelativeLayout> itemList,
                            final ImageView[] commonList, final ImageView[] sortList, View itemView) {
        mHScrollViews_hh.add(item_scroll_title);

        for (int i = 0; i < itemList.size(); i++) {
            final int position = i;
            itemList.get(i).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    collapseSoftInputMethod(v.getWindowToken());
                    if ((position + 1) != sortPosition_hh) {
                        sortPosition_hh = position + 1;
                        isSortDown_hh = true;
                    } else {
                        isSortDown_hh = !isSortDown_hh;
                    }
                    sortImageChange(commonList, sortList, position, isSortDown_hh);
                    ArrayList<QueryFundListBean.DataBean> maps = new ArrayList<>();
                    if (isSortDown_hh) {
                        maps.addAll(FundListSortUtils.sortListDown(list_hh, position, 0));
                    } else {
                        maps.addAll(FundListSortUtils.sortListUp(list_hh, position, 0));
                    }
                    list_hh.clear();
                    list_hh.addAll(maps);
                    if (hhAdapter != null) {
                        hhAdapter.notifyDataSetChanged();
                    }
                }
            });
        }

        lv_hh = (ListView) itemView.findViewById(R.id.hlistview_scroll_list);
        ll_item_hh.addView(itemView);

        hhAdapter = new ScrollAdapter(mActivity, R.layout.common_item_hlistview,
                new int[]{R.id.item_titlev, R.id.item_datav1, R.id.item_datav2, R.id.item_datav3, R.id.item_datav4,
                        R.id.item_datav5, R.id.item_datav6, R.id.item_datav7, R.id.item_datav8, R.id.item_icon_new,
                        R.id.item_icon_tui, R.id.item_titlev_code, R.id.item_datav1_1},
                list_hh, 7, FundListAllActivity.this, mHScrollViews_hh, lv_hh);
        lv_hh.setAdapter(hhAdapter);

        lv_hh.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                // scrollState:1--滑动开始，0--滑动结束,2--手指离开惯性滑动
                if (scrollState == 1) {
                    for (CHScrollView_Others scrollView : mHScrollViews_hh) {
                        if (mTouchView != scrollView) {
                            scrollView.smoothScrollTo(current_X_hh, current_Y_hh);
                        }
                        canChange_hh = false;
                    }
                } else if (scrollState == 2) {
                    canChange_hh = false;
                } else {
                    canChange_hh = true;
                }
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            }
        });

        if (!isFirstHH) {
            sortImageChange(commonList, sortList, 1, isSortDown_hh);
            ArrayList<QueryFundListBean.DataBean> maps = new ArrayList<>();
            if (isSortDown_hh) {
                maps.addAll(FundListSortUtils.sortListDown(list_hh, 1, 0));
            } else {
                maps.addAll(FundListSortUtils.sortListUp(list_hh, 1, 0));
            }
            list_hh.clear();
            list_hh.addAll(maps);
            if (hhAdapter != null) {
                hhAdapter.notifyDataSetChanged();
            }
        }
        isFirstHH = true;
    }

    /**
     * 初始化QDII基金列表
     */
    @SuppressLint("InflateParams")
    private void initQDList(CHScrollView_Others item_scroll_title, ArrayList<RelativeLayout> itemList,
                            final ImageView[] commonList, final ImageView[] sortList, View itemView) {
        mHScrollViews_QD.add(item_scroll_title);

        for (int i = 0; i < itemList.size(); i++) {
            final int position = i;
            itemList.get(i).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    collapseSoftInputMethod(v.getWindowToken());
                    if ((position + 1) != sortPosition_QD) {
                        sortPosition_QD = position + 1;
                        isSortDown_QD = true;
                    } else {
                        isSortDown_QD = !isSortDown_QD;
                    }
                    sortImageChange(commonList, sortList, position, isSortDown_QD);
                    ArrayList<QueryFundListBean.DataBean> maps = new ArrayList<>();
                    if (isSortDown_QD) {
                        maps.addAll(FundListSortUtils.sortListDown(list_QD, position, 0));
                    } else {
                        maps.addAll(FundListSortUtils.sortListUp(list_QD, position, 0));
                    }
                    list_QD.clear();
                    list_QD.addAll(maps);
                    if (QDAdapter != null) {
                        QDAdapter.notifyDataSetChanged();
                    }
                }
            });
        }

        lv_QD = (ListView) itemView.findViewById(R.id.hlistview_scroll_list);
        ll_item_QD.addView(itemView);

        QDAdapter = new ScrollAdapter(mActivity, R.layout.common_item_hlistview,
                new int[]{R.id.item_titlev, R.id.item_datav1, R.id.item_datav2, R.id.item_datav3, R.id.item_datav4,
                        R.id.item_datav5, R.id.item_datav6, R.id.item_datav7, R.id.item_datav8, R.id.item_icon_new,
                        R.id.item_icon_tui, R.id.item_titlev_code, R.id.item_datav1_1},
                list_QD, 8, FundListAllActivity.this, mHScrollViews_QD, lv_QD);
        lv_QD.setAdapter(QDAdapter);

        lv_QD.setOnScrollListener(new AbsListView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
                // scrollState:1--滑动开始，0--滑动结束,2--手指离开惯性滑动
                if (scrollState == 1) {
                    for (CHScrollView_Others scrollView : mHScrollViews_QD) {
                        if (mTouchView != scrollView) {
                            scrollView.smoothScrollTo(current_X_QD, current_Y_QD);
                        }
                        canChange_QD = false;
                    }
                } else if (scrollState == 2) {
                    canChange_QD = false;
                } else {
                    canChange_QD = true;
                }
            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            }
        });

        if (!isFirstQD) {
            sortImageChange(commonList, sortList, 1, isSortDown_QD);
            ArrayList<QueryFundListBean.DataBean> maps = new ArrayList<>();
            if (isSortDown_QD) {
                maps.addAll(FundListSortUtils.sortListDown(list_QD, 1, 0));
            } else {
                maps.addAll(FundListSortUtils.sortListUp(list_QD, 1, 0));
            }
            list_QD.clear();
            list_QD.addAll(maps);
            if (QDAdapter != null) {
                QDAdapter.notifyDataSetChanged();
            }
        }
        isFirstQD = true;
    }

    /**
     * 点击排序按钮的UI变化
     *
     * @param commonList
     * @param sortList
     * @param changePosition
     * @param sortDown       是否是降序
     */
    private void sortImageChange(ImageView[] commonList, ImageView[] sortList, int changePosition, boolean sortDown) {
        if (changePosition < 0) {
            for (int i = 0; i < commonList.length; i++) {
                commonList[i].setVisibility(View.VISIBLE);
            }

            for (int i = 0; i < sortList.length; i++) {
                sortList[i].setVisibility(View.GONE);
            }
        } else {
            for (int i = 0; i < commonList.length; i++) {
                if (i == changePosition) {
                    commonList[i].setVisibility(View.GONE);
                } else {
                    commonList[i].setVisibility(View.VISIBLE);
                }
            }

            for (int i = 0; i < sortList.length; i++) {
                if (i == changePosition) {
                    sortList[i].setVisibility(View.VISIBLE);
                    if (sortDown) {
                        sortList[i].setImageResource(R.mipmap.icon_rank_down);
                    } else {
                        sortList[i].setImageResource(R.mipmap.icon_rank_up);
                    }
                } else {
                    sortList[i].setVisibility(View.GONE);
                }
            }
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_all:
                clickChange(tv_all, iv_all);
                currentType = 9;

                if (isLoadSuccess) {
                    viewVisibile(11);
                    if (!isFirstALL) {
//                        initAllList();
                        isFirstALL = true;
                        initMultipleFundList(rl_all, list_all_01, list_all_02, list_all, rl_alls
                                , product_name_txt_all);
                        initView_all();
                    }
                } else {
                    getInfos();
                }
                break;
            case R.id.ll_hb:
                clickChange(tv_hb, iv_hb);
                currentType = 2;

                if (isLoadSuccess) {
                    viewVisibile(3);
                    if (!isFirstHB) {
                        initSingleFundList(2);
                    }
                } else {
                    getInfos();
                }
                break;
            case R.id.ll_lc:
                clickChange(tv_lc, iv_lc);
                currentType = 3;

                if (isLoadSuccess) {
                    viewVisibile(4);
                    if (!isFirstLC) {
                        initSingleFundList(3);
                    }
                } else {
                    getInfos();
                }
                break;
            case R.id.ll_fof:
                clickChange(tv_fof, iv_fof);
                currentType = 10;

                if (isLoadSuccess) {
                    viewVisibile(12);
                    if (!isFirstFOF) {
                        initSingleFundList(10);
                    }
                } else {
                    getInfos();
                }
                break;
            case R.id.ll_gp:
                clickChange(tv_gp, iv_gp);
                currentType = 4;

                if (isLoadSuccess) {
                    viewVisibile(5);
                    if (!isFirstGP) {
                        initSingleFundList(4);
                    }
                } else {
                    getInfos();
                }
                break;
            case R.id.ll_zq:
                clickChange(tv_zq, iv_zq);
                currentType = 5;

                if (isLoadSuccess) {
                    viewVisibile(6);
                    if (!isFirstZQ) {
                        initSingleFundList(5);
                    }
                } else {
                    getInfos();
                }
                break;
            case R.id.ll_zs:
                clickChange(tv_zs, iv_zs);
                currentType = 6;

                if (isLoadSuccess) {
                    viewVisibile(7);
                    if (!isFirstZS) {
                        initSingleFundList(6);
                    }
                } else {
                    getInfos();
                }
                break;
            case R.id.ll_hh:
                clickChange(tv_hh, iv_hh);
                currentType = 7;

                if (isLoadSuccess) {
                    viewVisibile(8);
                    if (!isFirstHH) {
                        initSingleFundList(7);
                    }
                } else {
                    getInfos();
                }
                break;
            case R.id.ll_QD:
                currentType = 8;
                clickChange(tv_QD, iv_QD);

                if (isLoadSuccess) {
                    viewVisibile(9);
                    if (!isFirstQD) {
                        initSingleFundList(8);
                    }
                } else {
                    getInfos();
                }
                break;

            default:
                break;
        }
    }

    /**
     * 隐藏显示对应的基金view容器
     *
     * @param tabNum tab位置
     */
    private void viewVisibile(int tabNum) {
        for (View view : visibileList) {
            view.setVisibility(View.GONE);
        }
        switch (tabNum) {
            case 10:
                tv_noInfo.setVisibility(View.VISIBLE);
                break;
            case 3:
                if (list_hb != null && list_hb.size() > 0) {
                    ll_item_hb.setVisibility(View.VISIBLE);
                }
                break;
            case 4:
                if (list_lc != null && list_lc.size() > 0) {
                    ll_item_lc.setVisibility(View.VISIBLE);
                }
                break;
            case 5:
                if (list_gp != null && list_gp.size() > 0) {
                    ll_item_gp.setVisibility(View.VISIBLE);
                }
                break;
            case 6:
                if (list_zq != null && list_zq.size() > 0) {
                    ll_item_zq.setVisibility(View.VISIBLE);
                }
                break;
            case 7:
                if (list_zs != null && list_zs.size() > 0) {
                    ll_item_zs.setVisibility(View.VISIBLE);
                }
                break;
            case 8:
                if (list_hh != null && list_hh.size() > 0) {
                    ll_item_hh.setVisibility(View.VISIBLE);
                }
                break;
            case 9:
                if (list_QD != null && list_QD.size() > 0) {
                    ll_item_QD.setVisibility(View.VISIBLE);
                }
                break;
            case 11:
                if (list_all != null && list_all.size() > 0) {
                    rl_all.setVisibility(View.VISIBLE);
                }
                break;
            case 12:
                if (list_fof != null && list_fof.size() > 0) {
                    ll_item_fof.setVisibility(View.VISIBLE);
                }
                break;
            default:
                break;
        }
    }

    /**
     * 点击改变文字颜色及大小
     *
     * @param textView
     * @param imageView
     */
    private void clickChange(TextView textView, ImageView imageView) {
        for (TextView tv : tv_lists) {
            tv.setTextColor(getResources().getColor(R.color.gray_01));
            tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources()
                    .getDimensionPixelOffset(R.dimen.nomarl_text_size));
            TextPaint tp = tv.getPaint();
            tp.setFakeBoldText(false);
        }
        textView.setTextColor(getResources().getColor(R.color.gongyin_nomarl_red));
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources()
                .getDimensionPixelOffset(R.dimen.big_text_size));
        TextPaint tp = textView.getPaint();
        tp.setFakeBoldText(true);

//        for (ImageView iv : iv_lists) {
//            iv.setVisibility(View.INVISIBLE);
//        }
//        imageView.setVisibility(View.VISIBLE);
    }

    public void addHViews(final CHScrollView_Others hScrollView, List<CHScrollView_Others> chScrollView_others, ListView listView) {
        if (!chScrollView_others.isEmpty()) {
            int size = chScrollView_others.size();
            CHScrollView_Others scrollView = chScrollView_others.get(size - 1);
            final int scrollX = scrollView.getScrollX();
            if (scrollX != 0) {
                listView.post(new Runnable() {
                    @Override
                    public void run() {
                        hScrollView.scrollTo(scrollX, 0);
                    }
                });
            }
        }
        chScrollView_others.add(hScrollView);
    }

    @Subscribe
    public void onScrollChange_hb(OnScrollEvent_Hb event) {
        if (canChange_hb) {
            Log.d("OnScrollEvent", "OnScrollEvent");
            current_X_hb = event.getL();
            current_Y_hb = event.getT();
            for (CHScrollView_Others scrollView : mHScrollViews_hb) {
                scrollView.smoothScrollTo(event.getL(), event.getT());
            }
        }
    }

    @Subscribe
    public void onScrollChange_lc(OnScrollEvent_Lc event) {
        if (canChange_lc) {
            Log.d("OnScrollEvent", "OnScrollEvent");
            current_X_lc = event.getL();
            current_Y_lc = event.getT();
            for (CHScrollView_Others scrollView : mHScrollViews_lc) {
                scrollView.smoothScrollTo(event.getL(), event.getT());
            }
        }
    }

    @Subscribe
    public void onScrollChange_gp(OnScrollEvent_Gp event) {
        if (canChange_gp) {
            Log.d("OnScrollEvent", "OnScrollEvent");
            current_X_gp = event.getL();
            current_Y_gp = event.getT();
            for (CHScrollView_Others scrollView : mHScrollViews_gp) {
                scrollView.smoothScrollTo(event.getL(), event.getT());
            }
        }
    }

    @Subscribe
    public void onScrollChange_zq(OnScrollEvent_Zq event) {
        if (canChange_zq) {
            Log.d("OnScrollEvent", "OnScrollEvent");
            current_X_zq = event.getL();
            current_Y_zq = event.getT();
            for (CHScrollView_Others scrollView : mHScrollViews_zq) {
                scrollView.smoothScrollTo(event.getL(), event.getT());
            }
        }
    }

    @Subscribe
    public void onScrollChange_zs(OnScrollEvent_Zs event) {
        if (canChange_zs) {
            Log.d("OnScrollEvent", "OnScrollEvent");
            current_X_zs = event.getL();
            current_Y_zs = event.getT();
            for (CHScrollView_Others scrollView : mHScrollViews_zs) {
                scrollView.smoothScrollTo(event.getL(), event.getT());
            }
        }
    }

    @Subscribe
    public void onScrollChange_hh(OnScrollEvent_Hh event) {
        if (canChange_hh) {
            Log.d("OnScrollEvent", "OnScrollEvent");
            current_X_hh = event.getL();
            current_Y_hh = event.getT();
            for (CHScrollView_Others scrollView : mHScrollViews_hh) {
                scrollView.smoothScrollTo(event.getL(), event.getT());
            }
        }
    }

    @Subscribe
    public void onScrollChange_QD(OnScrollEvent_QDII event) {
        if (canChange_QD) {
            Log.d("OnScrollEvent", "OnScrollEvent");
            current_X_QD = event.getL();
            current_Y_QD = event.getT();
            for (CHScrollView_Others scrollView : mHScrollViews_QD) {
                scrollView.smoothScrollTo(event.getL(), event.getT());
            }
        }
    }

    @Subscribe
    public void onScrollChange_fof(OnScrollEvent_Fof event) {
        if (canChange_fof) {
            Log.d("OnScrollEvent", "OnScrollEvent");
            current_X_fof = event.getL();
            current_Y_fof = event.getT();
            for (CHScrollView_Others scrollView : mHScrollViews_fof) {
                scrollView.smoothScrollTo(event.getL(), event.getT());
            }
        }
    }

    private void gotoDetails(QueryFundListBean.DataBean bean) {
        etSearch.setCursorVisible(false);
        Intent intent = new Intent().setClass(this, FundDetailActivity.class);
        intent.putExtra("fundcode", bean.getFundcode());
        intent.putExtra("fundname", bean.getFundname());
        intent.putExtra("fundType", bean.getFundtype());
        intent.putExtra("mainTitle", bean.getFundname() + " " + bean.getFundcode());
        intent.putExtra("subTitle", bean.getFundstateDescription());
        startActivity(intent);
    }
}